/*
 * CommonElement.h
 *
 *  Created on: 2010-6-4
 *      Author: Guobc
 */

#ifndef COMMONELEMENT_H_
#define COMMONELEMENT_H_

#include <string>
#include "ASTNode.h"
#include "Element.h"

namespace HA {
class CommonElement: public HA::Element {
public:
	CommonElement();
	CommonElement(ASTDom* document, int start, int end);

	/**
	 * Sets string contents of the node
	 * @param text The new text for the node
	 */
	inline void setText(const string& text) {

	}

	/**
	 * Returns the text of the node.
	 * @return The contents of the string or remark node, and in the case of
	 * a tag, the contents of the tag less the enclosing angle brackets.
	 */
	string getText();

	/**
	 * Set start tag to this element.
	 * @param name The start tag.
	 */
	inline void setStartTag(Tag& tag) {
		startTag = tag;
	}

	/**
	 * Get start tag to this element.
	 * @param name The start tag.
	 */
	Tag getStartTag() const {
		return startTag;
	}

	/**
	 * Set end tag to this element.
	 * @param name The end tag name.
	 */
	inline void setEndTag(Tag& tag) {
		endTag = tag;
	}

	/**
	 * Get end tag of this element.
	 * @param name The end tag.
	 */
	inline Tag getEndTag() const {
		return endTag;
	}

	/**
	 * Set element name.
	 * @param
	 */
	inline void setElementName(const string& name) {
		mName = name;
	}

	/**
	 * Get element name
	 * @return
	 */
	inline string getElementName() const {
		return startTag.getTagName().empty() ? mName : startTag.getTagName();
	}

	/**
	 * Sets attribute with given key and value.
	 * @param key The key of attribute.
	 * @param value The value of attribute.
	 */
	inline void setAttribute(const string& key, const string& value) {
		startTag.setAttribute(key, value);
	}

	/**
	 * Gets the value of attribute with given key.
	 * @param key The key of attribute.
	 */
	inline string getAttribute(const string& key) {
		return startTag.getAttribute(key);
	}

	/**
	 * Remove the the attribute with given key, if it exits.
	 * @param key The key of attribute.
	 */
	inline void removeAttribute(const string& key) {
		startTag.removeAttribute(key);
	}

	/**
	 * Return the set of names handled by this element.
	 * Since this a a generic element, it has no ids.
	 * @return The names to be matched that create elements of this type.
	 */
	string* getIds() const;

	/**
	 * Return the set of element names that cause this element to finish.
	 * These are the normal (non end elements) that if encountered while
	 * scanning (a composite element) will cause the generation of a
	 * element.
	 * Since this a a non-composite element, the default is no enders.
	 * @return The names of following elements that stop further scanning.
	 */
	string* getEnders() const;

	/**
	 * Return the HTML for this node.
	 * This should be the sequence of characters that were encountered by
	 * the parser that caused this node to be created. Where this breaks down is
	 * where broken nodes (tags and remarks) have been encountered and fixed.
	 * Applications reproducing html can use this method on nodes which are to
	 * be used or transferred as they were received or created.
	 * @return The sequence of characters that would cause this node
	 * to be returned by the parser or lexer.
	 */
	string toHTML();

	/**
	 * Allow creating an instance of this node.
	 * @return A new instance of this node.
	 */
	inline ASTNode* newInstance() const {
		return new CommonElement();
	}

	/**
	 * Test whether this element is an empty element.
	 * An empty element has no content and it's end tag is closed in the start tag.
	 * such as '<br />' tag.
	 * @return True if has content, false otherwise.
	 */
	inline bool isEmptyElement() {
		return startTag.hasEndTag();
	}

	~CommonElement();

protected:
	Tag startTag;
	Tag endTag;
	string mName;
};
}

#endif /* COMMONELEMENT_H_ */
